/*
 * @description: 
 * @Author: wzg
 * @Date: 2021-03-19 14:21:52
 * @LastEditTime: 2021-03-22 11:22:50
 */
import { join } from 'path';//引入原生path模块
import pkg from 'koa-log4';
const { configure, koaLogger, getLogger } = pkg;
// import { configure, koaLogger, getLogger } from 'koa-log4';//引入koa-log4
configure({
  appenders: {
    //访问日志
    access: {
      type: 'dateFile',
      pattern: '-yyyy-MM-dd.log', //通过日期来生成文件
      alwaysIncludePattern: true, //文件名始终以日期区分
      encoding: "utf-8",
      filename: join('logs/', 'access.log') //生成文件路径和文件名
    },
    //系统日志
    application: {
      type: 'dateFile',
      pattern: '-yyyy-MM-dd.log', //通过日期来生成文件
      alwaysIncludePattern: true, //文件名始终以日期区分
      encoding: "utf-8",
      filename: join('logs/', 'application.log') //生成文件路径和文件名
    },
    out: {
      type: 'console'
    }
  },
  categories: {
    default: { appenders: ['out'], level: 'info' },
    access: { appenders: ['access'], level: 'info' },
    application: { appenders: ['application'], level: 'WARN' }
  }
});

export function accessLogger () { return koaLogger(getLogger('access')); } //记录所有访问级别的日志
export const systemLogger = getLogger('application');  //记录所有应用级别的日志